package gold.digger;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by fanzhenyu02 on 2020/2/25.
 */
public class LC5441 {


    public String[] getFolderNames(String[] names) {
        String[] res = new String[names.length];
        Map<String, Integer> dict = new HashMap<>();
        for (int i = 0; i < names.length; i++) {
            if (dict.containsKey(names[i])) {
                int existNameCount = dict.get(names[i]);
                String afterName = names[i] + "(" + existNameCount + ")";
                while (dict.containsKey(afterName)) {
                    afterName = names[i] + "(" + ++existNameCount + ")";
                }

                res[i] = afterName;
                dict.put(names[i], existNameCount);
            } else {
                res[i] = names[i];
            }

            dict.put(res[i], 1);
        }

        return res;
    }

    public static void main(String[] args) {
        LC5441 an = new LC5441();
        String[] names = {};
        System.out.println(an.getFolderNames(names));
    }


}
